package com.dream.service.recommender.hub.util;

import com.dream.service.recommender.domain.model.UserInfo;
import com.dream.service.recommender.domain.request.FrontParam;

import java.util.Map;

/**
 * Created by zhiji on 2016/04/25.
 */
public class ParamUtil {

    public static Map getExtraValues(FrontParam frontParam){
        if(frontParam == null || frontParam.getExtra_values()== null){
            return null;
        }
        return frontParam.getExtra_values();

    }

    public static Long getSpu(FrontParam frontParam){
        if(frontParam == null||frontParam.getSpu()==null){
            return -1L;
        }
        return frontParam.getSpu() == null ? -1 : frontParam.getSpu();
    }

    public static int getPage(FrontParam frontParam){
        if(frontParam == null || frontParam.getPage_info() == null){
            return 1;
        }
        int page = frontParam.getPage_info().getPage_num();
        return page < 1 ? 1 : page;
    }

    public static int getPageSize(FrontParam frontParam){
        if(frontParam == null || frontParam.getPage_info() == null){
            return 20;
        }
        int pagesize = frontParam.getPage_info().getPage_size();
        return (pagesize <= 0|| pagesize >= 100) ? 20 : pagesize;
    }

    public static UserInfo getUser(FrontParam frontParam){
        if(frontParam == null || frontParam.getUser() == null){
            return null;
        }
        return frontParam.getUser();
    }

    public static String getUUid(FrontParam frontParam){
        if(frontParam == null || frontParam.getUser() == null){
            return null;
        }
        return frontParam.getUser().getUuid();
    }

    public static String getPin(FrontParam frontParam){
        if(frontParam == null || frontParam.getUser() == null){
            return null;
        }
        return frontParam.getUser().getPin();
    }

    public static int getCid(FrontParam frontParam){
        if(frontParam == null){
            return -1;
        }
        return frontParam.getCid() == null ? -1 : frontParam.getCid();
    }
}
